<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">按钮</div>

    <script>
        let app = document.getElementById('app')
        // app.onclick = function() {}

        // function addEvent(type, el, fn) {
        //     if (window.addEventListener) {
        //         el.addEventListener(type, fn, false)
        //     } else if (window.attachEvent) {
        //         el.attachEvent('on' + type, fn)
        //     }
        // }

        function addEvent(type, el, fn) {
            if (window.addEventListener) {
                addEvent =function(type, el, fn) { 
                    el.addEventListener(type, fn, false) 
                }
            } else if (window.attachEvent) {
                addEvent =function(type, el, fn) { 
                    el.attachEvent('on' + type, fn) 
                }
            }
            return addEvent()
        }
        
    </script>
</body>

</html>